


	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

*-------------------------------------------------------------------------------
* 1961
*-------------------------------------------------------------------------------

import delimited "data/inputs/Census1961.csv", clear 

gen MenosDePrimaria = (pob-prim-bachiller-licen)/pob
gen Primaria = prim / pob
gen Bachiller = bach / pob
gen Licenciado = lic / pob

keep if year == 1961
keep year Menos Prim Bach Lic 

tempfile censo1961
save `censo1961'


	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	
*-------------------------------------------------------------------------------
* 1981
*-------------------------------------------------------------------------------


* First table
*------------

	/* Note, this crosstab allows construction of
	   number of people with primary complete, secondary complete, etc.,
	   but does not include the denominator 
	   (i.e. does not include people with less than one year
	   of primary ed). We get the denominator from the next
	   table. */


import excel "data/inputs/Census1981a.xlsx", sheet("Proc10 T_Dist") clear

* variable names
drop in 1/12
compress
foreach var of varlist C-F {
	local name = strtoname(`var'[1])
	rename `var' `name'
	}
drop in 1/1
rename B year_study
keep year-Total
renvars *Primaria *Secundaria *Superior, predrop(4)
destring year-Total, replace force

* organize
drop if year == .
drop Total
gen year = 1981

* proportions of interest
reshape wide Primaria Secundaria Superior, i(year) j(year_study)
order year Primaria* Secundaria* Superior*
egen Primaria_Completa = rowtotal(Primaria6-Secundaria4)
egen Secundaria_Completa = rowtotal(Secundaria5-Superior4)
egen Superior_Completa = rowtotal(Superior5-Superior8)
keep year *Completa

* save
tempfile completa1981
save `completa1981'


* Second table
*--------------

	/* Note, this crosstab does not have number 
	   of people with primary COMPLETE, but does 
	   allow construction of the denominator. 
	   */
	   
import excel "data/inputs/Census1981b.xlsx", sheet("Proc1 T_Dist") clear

* variable names
drop in 1/10
compress
foreach var of varlist C-G {
	local name = strtoname(`var'[1])
	rename `var' `name'
	}
drop in 1/1
rename B age
keep age-Total
destring age, replace force
drop if age == . /* Total lines */
renvars *Ninguno *Primaria *Secundaria *Superior, predrop(4)

* organize
destring Ninguno-Total, replace force
keep if age >= 18
collapse (sum) Total
gen year = 1981


* Merge two tables
*-----------------

merge 1:1 year using `completa1981'


* Take total from second table and counts from first table
*---------------------------------------------------------

* proportions
gen MenosDePrimaria = Total - (Primaria_Completa + Secundaria_Completa + Superior_Completa)
renvars *Completa, postdrop(9)
foreach var of varlist MenosDePrimaria Primaria Secundaria Superior {
	gen p_`var' = `var' / Total
	}
keep year p_*

* remame
rename p_MenosDePrimaria MenosDePrimaria
rename p_Primaria Primaria
rename p_Secundaria Bachiller
rename p_Superior Licenciado	

* save
tempfile censo1981
save `censo1981'
	
	
	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

*-------------------------------------------------------------------------------
* 1990
*-------------------------------------------------------------------------------

import excel "data/inputs/Census1990.xlsx", sheet("Proc1 T_Dist") clear	

* variable names
drop in 1/10
compress
foreach var of varlist C-I {
	local name = strtoname(`var'[1])
	rename `var' `name'
	}
drop in 1/1
rename B age
keep age-Total
renvars *NINGUNO *PRE_ESCOLAR *PRIMARIA_BASICA *MEDIA_BASICA *SUPERIOR *DIVERSIFICADA, predrop(4)

* organize
destring age-Total, replace force
drop if age == . /* Total lines */
keep if age >= 18

* proportions
collapse (sum) NINGUNO-Total
foreach var of varlist NINGUNO-SUPERIOR {
	gen p_`var' = `var' / Total
	}
keep p_*

* names
gen year = 1990
gen MenosDePrimaria = p_NINGUNO + p_PRE_ESCOLAR
gen Primaria = p_PRIMARIA_BASICA + p_MEDIA_BASICA
rename p_DIVERSIFICADA Bachiller
rename p_SUPERIOR Licenciado	
keep year Menos Prim Bach Lic 

* save
tempfile censo1990
save `censo1990'
	
	
	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

*-------------------------------------------------------------------------------
* 2001
*-------------------------------------------------------------------------------

import excel "data/inputs/Census2001.xlsx", sheet("Proc2 T_Dist") clear

* variable names
drop in 1/10
compress
foreach var of varlist C-L {
	local name = strtoname(`var'[1])
	rename `var' `name'
	}
drop in 1/1
rename B age

* organize
keep age-Total
renvars *No_declarado *Ninguno *Preescolar *Básica___Primaria *Educación_Especial *Media *Técnico_Medio *Técnico_Superior *Universitario, predrop(4)
destring age-Total, replace force
drop if age == . /* Total lines */
keep if age >= 18

* proportions
collapse (sum) No_declarado-Total
foreach var of varlist No_declarado-Universit {
	gen p_`var' = `var' / Total
	}
keep p_*
gen MenosDePrimaria = p_Ninguno + p_Preescolar
gen Primaria = p_Básica___Primaria
gen Bachiller = p_Media + p_Técnico_Medio + p_Técnico_Superior
rename p_Universitario Licenciado

* save
gen year = 2001	
keep year Menos Prim Bach Lic 
tempfile censo2001
save `censo2001'



	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

*-------------------------------------------------------------------------------
* 2011
*-------------------------------------------------------------------------------

import excel "data/inputs/Census2011.xlsx", sheet("Proc1 T_Dist") clear

* variable names
drop in 1/10
compress
foreach var of varlist C-J {
	local name = strtoname(`var'[1])
	rename `var' `name'
	}
drop in 1/1
rename B age

* organize
keep age-Total
renvars age-Total, subst(__ )
renvars _*, predrop(2)
destring age-Total, replace force
drop if age == . /* Total lines */
keep if age >= 18

* proportions
collapse (sum) No_sabe-Total
foreach var of varlist No_sabe-Universit {
	gen p_`var' = `var' / Total
	}
gen MenosDePrimaria = p_Ninguno + p_InicialPreescolar_
rename p_Primaria1_6_ Primaria
gen Bachiller = p_Secundaria1_5_6_ + p_Técnico_Superior
rename p_Universitario Licenciado

* save
gen year = 2011
keep year Menos Primaria Bach Lic 
tempfile censo2011
save `censo2011'



	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	
*-------------------------------------------------------------------------------
* append
*-------------------------------------------------------------------------------

clear
foreach year in 1961 1981 1990 2001 2011 {
	append using `censo`year''
	}
order year Menos 


* End of subfile
